#include "../include/TcpServer.h"

extern int pipefd[2];
// 启动服务器与关闭服务器
void TcpServer::start() {
    _acceptor.ready();
    pid_t pid = fork();

    if (pid == 0) {  // 子进程 写
        //printf("I'm the child process. PID = %d\n", getpid());
        close(pipefd[0]);
        while (1) {
            write(pipefd[1], "x", 1);   // 每秒写入一个字节
            sleep(1);               // 睡眠1秒
        }
    } else {  // 父进程 读
        // printf("I'm the parent process. PID = %d, child PID = %d\n", getpid(),
        //        pid);

        close(pipefd[1]);

        _loop.loop();
    }
}